<template>
  <view class="page" :style="themeColor">
    <view class="flex benben-position-layout flex flex-wrap align-center bindingEmail_flex_0"
      :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
      <view class='flex flex-wrap align-center justify-between flex-sub bindingEmail_fd0_0'>
        <view class='flex flex-wrap align-center' @tap.stop="handleJumpDiy" data-type="back" data-url="1">
          <text class='fu-iconfont2  bindingEmail_fd0_0_c0_c0'>&#xE794;</text>
        </view>
        <view class='flex flex-wrap align-stretch justify-center flex-sub'>
          <text class='bindingEmail_fd0_0_c1_c0'>绑定新邮箱</text>
        </view>
        <view class='flex flex-wrap align-center bindingEmail_fd0_0_c2'>
        </view>
      </view>

    </view>
    <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>

    <view class="flex flex-direction flex-wrap align-stretch bindingEmail_flex_1">
      <view class='flex flex-wrap align-center bindingEmail_fd1_0'>
        <text class='bindingEmail_fd1_0_c0'>新邮箱号码</text>
        <input class='flex-sub bindingEmail_fd1_0_c1' type="text" :focus='true' placeholder="请输入新的邮箱号"
          confirm-type="done" :maxlength="22" placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx"
          v-model="newPhone" />
      </view>
      <view class='flex flex-wrap align-center bindingEmail_fd1_0'>
        <text class='bindingEmail_fd1_0_c0'>验证码验证</text>
        <input class='flex-sub bindingEmail_fd1_1_c1' type="number" placeholder="请输入验证码" confirm-type="done"
          :maxlength="6" placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx" v-model="smsVerification" />
        <!--        <benben-send-verification-code class='flex  bindingEmail_fd1_1_c2' after-text='后重新获取' before-text='获取验证码'
          :type='type' :phone="phone" :email='newPhone' :area_code="list" @click.native="getemailcode">
        </benben-send-verification-code> -->
        <text class='flex  bindingEmail_fd1_1_c2' @tap.stop="getemailcode" v-if="xianshi==1">获取验证码</text>
        <text class='flex  bindingEmail_fd1_1_c2' v-else>{{countDown}}s后重新获取</text>
      </view>
      <button class='flex-sub bindingEmail_fd1_2' @tap.stop="bindNewPhoneNumberFunc()">完成</button>
    </view>




  </view>
</template>
<script>
  import {
    validate
  } from '@/common/utils/validate.js'
  export default {
    components: {},


    data() {
      return {
        "newPhone": "",
        "smsVerification": "",
        "phone": "",
        type: 7,
        list: "",
        email: '',
        xianshi: 1,
        countDown: 60, // 初始倒计时60秒
        timer: null // 定时器
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },

    },
    watch: {},
    onLoad(options) {
      let {
        email
      } = options
      if (email !== undefined) this.email = email
      console.log(this.email)
      let a = uni.getStorageSync("USER_INFO")
      console.log(a, 'aaa')
      this.phone = a.mobile
      this.list = a.area_code
    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {

    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      //获取邮箱验证码
      async getemailcode() {
        if (!validate(this.newPhone, 'require')) {
          this.$message.info('新邮箱号不能为空');
          return false;
        }
        if (!validate(this.newPhone, 'email')) {
          this.$message.info('请输入正确的新邮箱号');
          return false;
        }
        let res = await this.$api.post(global.apiUrls.a6473344de61d8, {
          email: this.newPhone,
          is_test: 1,
          type: this.type
        })
        if (res.data.code != 1) {
          this.$message.info(res.data.msg)
          return
        }
        this.$message.info(res.data.data.code)
        console.log(res.data.data.code, 'res.data.data.code')
        this.startCountDown()
      },
      startCountDown() {
        this.xianshi = 2
        this.timer = setInterval(() => {
          if (this.countDown > 0) {
            this.countDown--
          } else {
            clearInterval(this.timer)
            location.reload()
            this.xianshi = 1
          }
        }, 1000)
      },
      //绑定新手机号
      async bindNewPhoneNumberFunc() {
        if (!validate(this.newPhone, 'require')) {
          this.$message.info('新邮箱号不能为空');
          return false;
        }
        if (!validate(this.newPhone, 'email')) {
          this.$message.info('请输入正确的新邮箱号');
          return false;
        }
        if (!validate(this.smsVerification, 'require')) {
          this.$message.info('验证码不能为空');
          return false;
        }
        if (!validate(this.smsVerification, 'captcha')) {
          this.$message.info('请输入正确的验证码');
          return false;
        }
        let res = await this.$api.post(global.apiUrls.a647335dd9c4fa, {
          email: this.newPhone,
          code: this.smsVerification,
          type: this.type
        })
        if (res.data.code != 1) {
          this.$message.info(res.data.msg)
          return
        }
        this.$message.info(res.data.msg)
        setTimeout(() => {
          uni.navigateBack();
        }, 800)

      }
    }
  };
</script>
<style lang="scss" scoped>
  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: #fff;
    background-size: 100% auto !important;
  }

  .bindingEmail_flex_0 {
    border-bottom: 1px solid #eee;
    background: #fff;
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto !important;
  }

  .bindingEmail_fd0_0_c2 {
    width: 32rpx;
    height: 32rpx;
  }

  .bindingEmail_fd0_0_c1_c0 {
    font-size: 36rpx;
    font-weight: 500;
    color: #333;
    line-height: 88rpx;
  }

  .bindingEmail_fd0_0_c0_c0 {
    font-size: 32rpx;
    font-weight: 500;
    color: #333;
    line-height: 88rpx;
  }

  .bindingEmail_fd0_0 {
    margin: 0rpx 32rpx 0rpx 32rpx;
  }

  .bindingEmail_flex_1 {
    background: #fff;
    font-size: 32rpx;
    background-size: 100% auto !important;
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .bindingEmail_fd1_2 {
    background: var(--benbenbgColor2);
    border-radius: 100rpx 100rpx 100rpx 100rpx;
    font-size: 32rpx;
    color: #fff;
    height: 88rpx;
    line-height: 88rpx;
    width: 686rpx;
    font-weight: 400;
    margin: 80rpx 0rpx 0rpx 0rpx;
  }

  .bindingEmail_fd1_1_c2 {
    font-size: 32rpx;
    font-weight: 400;
    color: var(--benbenFontColor4);
  }

  .bindingEmail_fd1_1_c1 {
    line-height: 45rpx;
    color: #333;
    font-size: 32rpx;
    font-weight: 400;
  }

  .bindingEmail_fd1_0_c1 {
    line-height: 45rpx;
    font-size: 28rpx;
    font-weight: 400;
    color: #333;
  }

  .bindingEmail_fd1_0_c0 {
    font-size: 32rpx;
    font-weight: 400;
    font-style: normal;
    color: #333;
    width: 182rpx;
  }

  .bindingEmail_fd1_0 {
    border-bottom: 1px solid #eee;
    padding: 32rpx 0rpx 32rpx 0rpx;
  }
</style>
